<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache">
	<meta http-equiv="Expires" content="0">
<title>登录</title>
	<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../css/admin.css"/>
	<link rel="icon" href="../../img/test/ycLogo.png" type="image/x-icon"/>

</head>
<body  background="../../img/test/lgbg.jpg">
<div>
	<div class="container" align="center">

		<div class="panel panel-default main_panel">
			<div class="panel-body">
				<div class="logo">
					<img alt="后台" src="../../img/test/ycLogo.png">
				</div>
				<div class="form">
					<form id="login-form" role="form" method="post" onsubmit="return false;">
						<div class="form-group">
							<div class="input-group input1">
								<div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div>
								<input class="form-control" id="username" name="username" placeholder="用户名" type="text"
									   autocomplete="off">
							</div>
						</div>
						<div class="form-group">
							<div class="input-group input1">
								<div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div>
								<input  class="form-control" id="password" name="password" placeholder="密码" type="password"
									   autocomplete="off">
							</div>
						</div>

						<div>
							<button class="btn btn-primary login_btn" type="submit"
									onclick="login(this)" style="width: 120px;">登录</button>
						</div>
						<span id="info" style="color: red"></span>
					</form>
					<hr width="70%" />
				</div>
				<div><span style="color:#AAA;">—</span><span class="shadowfont"> 逸尘智创 </span><span style="color:#AAA;">—</span></div>
			</div>
		</div>
		<div><div style="color:#FFFFFF;">@汇聚组织的力量</div></div>
	</div>
</div>



</body>
<script src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
	if (top != self) {
		parent.location.href = '/login.html';
	}
	
	var token = localStorage.getItem("token");
	if (token != null && token.trim().length != 0) {
		$.ajax({
			type : 'get',
			url : '/users/current?token=' + token,
			success : function(data) {
				location.href = '/index.html';
			},
			error : function(xhr, textStatus, errorThrown) {
				var msg = xhr.responseText;
				var response = JSON.parse(msg);
				var code = response.code;
				var message = response.message;
				if (code == 401) {
					localStorage.removeItem("token");
				}
			}
		});
	}

	function login(obj) {
		$(obj).attr("disabled", true);

		var username = $.trim($('#username').val());
		var password = $.trim($('#password').val());
		if (username == "" || password == "") {
			$("#info").html('用户名或者密码不能为空');
			$(obj).attr("disabled", false);
		} else {
			$.ajax({
				type : 'post',
				url : '/login',
				data : $("#login-form").serialize(),
				success : function(data) {
					localStorage.setItem("token", data.token);
					location.href = '/index.html';
				},
				error : function(xhr, textStatus, errorThrown) {
					var msg = xhr.responseText;
					var response = JSON.parse(msg);
					$("#info").html(response.message);
					$(obj).attr("disabled", false);
				}
			});

		}
	}
</script>
</html>